/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package designersfo;


import designersfo.Cons.CellInfo;
import designersfo.Cons.CellInfo.CellFormat;
import designersfo.Cons.CellInfo.CustomContentCellData;
import designersfo.Cons.RowInfo;
import designersfo.EmptyV.ColInfo;
import java.io.File;
import java.util.Iterator;
import java.util.List;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;


/**
 *
 * @author rejun001
 */
public class TestDesignerSFO
{

    /**
     *
     * @param args
     */
    public static void main( String args[] )
    {

        TestDesignerSFO tds = new TestDesignerSFO();
        try
        {
            JAXBContext jc = JAXBContext.newInstance( "designersfo" );
            Unmarshaller um = jc.createUnmarshaller();
            Root root = (Root) um.unmarshal( new File( "massimo.xml" ) );

            List<Object> cvs = root.getConsVOrConsOrEmptyV();
            Iterator cvs_it = cvs.iterator();

            while ( cvs_it.hasNext() )
            {

                Object o = cvs_it.next();
                if ( o instanceof Cons )
                {
                    Cons cons = (Cons) o;
                    displayCons( cons );

                } else if ( o instanceof ConsV )
                {
                    ConsV consv = (ConsV) o;
                    displayConsV( consv );

                } else if ( o instanceof EmptyV )
                {
                    System.out.println( "It's an Empty V" );
                    EmptyV ev = (EmptyV) o;
                    displayEmptyV( ev );
                }

            }

            Marshaller m = jc.createMarshaller();
            m.marshal( root , System.out );


        } catch ( Exception e )
        {
            e.printStackTrace();
        }
    }


    /**
     *
     * @param ci
     */
    public static void displayCellInfo( CellInfo ci )
    {
        System.out.print( "CELLINFO: " );
        System.out.print( "joined-cell-index-v=" + ci.getJoinedCellIndexV() );
        System.out.print( ", joined-cell-index-h=" + ci.getJoinedCellIndexH() );
        System.out.print( ", joined-cell-count-v=" + ci.getJoinedCellCountV() );
        System.out.println( ", joined-cell-count-h=" + ci.getJoinedCellCountH() );

        String ncd = ci.getNullCellData();
        if ( ncd != null )
        {
            System.out.println( "Null Cell Data" );
        }

        List<CustomContentCellData> cccds = ci.getCustomContentCellData();
        Iterator cccds_it = cccds.iterator();
        while ( cccds_it.hasNext() )
        {
            CustomContentCellData cccd = (CustomContentCellData) cccds_it.next();
            System.out.println( "CCCD: content-id=" + cccd.getContentId() + ", relative-index=" + cccd.getRelativeIndex()
                    + ", tab-order=" + cccd.getTabOrder() + ", response=" + cccd.getResponse() );
        }

        List<CellFormat> cfs = ci.getCellFormat();
        Iterator cfs_it = cfs.iterator();
        while ( cfs_it.hasNext() )
        {
            CellFormat cf = (CellFormat) cfs_it.next();
            System.out.println( "CellFormat:\n\t: border: bottom-color=" + cf.getBorderBottomColor() + ", rb-corner-radius=" + cf.getBorderRbCornerRadius()
                    + ", right-style=" + cf.getBorderRightStyle() + ",right-color=" + cf.getBorderRightColor() + ", right-width=" + cf.getBorderRightWidth()
                    + ", rt-corner-radius=" + cf.getBorderRtCornerRadius() + ", top-style=" + cf.getBorderTopStyle() + ", top-color=" + cf.getBorderTopColor() );
            System.out.println( "\t: border: top-width=" + cf.getBorderTopWidth() + ", lt-corner-radius=" + cf.getBorderLtCornerRadius() + ", left-style=" + cf.getBorderLeftStyle()
                    + ", left-color=" + cf.getBorderLeftColor() + ", left-width=" + cf.getBorderLeftWidth() + ", lb-corner-radius=" + cf.getBorderLbCornerRadius()
                    + ", bottom-style=" + cf.getBorderBottomStyle() + ", bottom-color=" + cf.getBorderBottomColor() + ", bottom-width=" + cf.getBorderBottomWidth() );
            System.out.println( "\t: padding: left=" + cf.getPaddingLeft() + ", top=" + cf.getPaddingTop() + ", right=" + cf.getPaddingRight() + ", bottom=" + cf.getPaddingBottom() );
            System.out.println( "\t: background-color=" + cf.getBackgroundColor() + ", margin-colo=" + cf.getMarginColor() );
            System.out.println( "\t: font: family=" + cf.getFontFamily() + ", size=" + cf.getFontSize() + ", color=" + cf.getFontColor()
                    + ", style=" + cf.getFontStyle() + ", weight=" + cf.getFontWeight() + ", decoration=" + cf.getFontDecoration() + ", rotation-angle=" + cf.getFontRotationAngle() );
            System.out.println( "\t: has-leader=" + cf.getHasLeader() + ", has-goomer=" + cf.getHasGoomer() + ", horz_align=" + cf.getHorzAlignment()
                    + ", vert-align=" + cf.getVertAlignment() );
        }
    }


    /**
     *
     * @param cv
     */
    public static void displayConsV( ConsV cv )
    {
        System.out.print( "\t" );
        System.out.print( "CONSV\n" );

        List<Cons> cs = cv.getCons();
        Iterator cv_it = cs.iterator();
        while ( cv_it.hasNext() )
        {
            Cons cons = (Cons) cv_it.next();
            displayCons( cons );
        }

        List<ConsV> cvs = cv.getConsV();
        Iterator cvs_it = cvs.iterator();
        while ( cvs_it.hasNext() )
        {
            ConsV consv = (ConsV) cvs_it.next();
            displayConsV( consv );
        }

        List<EmptyV> evs = cv.getEmptyV();
        Iterator evs_it = evs.iterator();
        while ( evs_it.hasNext() )
        {
            EmptyV ev = (EmptyV) evs_it.next();
            displayEmptyV( ev );
        }

    }


    /**
     *
     * @param c
     */
    public static void displayCons( Cons c )
    {
        System.out.print( "\tCONS\n" );

        List<CellInfo> cis = c.getCellInfo();
        Iterator cis_it = cis.iterator();
        while ( cis_it.hasNext() )
        {
            CellInfo ci = (CellInfo) cis_it.next();
            displayCellInfo( ci );
        }

        List<Cons> conss = c.getCons();
        Iterator conss_it = conss.iterator();
        while ( conss_it.hasNext() )
        {
            Cons cons = (Cons) conss_it.next();
            displayCons( cons );
        }

        List<RowInfo> ris = c.getRowInfo();
        Iterator ris_it = ris.iterator();
        while ( ris_it.hasNext() )
        {
            RowInfo ri = (RowInfo) ris_it.next();
            System.out.println( "RowInfo: cell-size-v=" + ri.getCellSizeV() + ", can-break-before-v=" + ri.getCanBreakBeforeV()
                    + ", header-id=" + ri.getHeaderId() + ", header-left-padding=" + ri.getHeaderLeftPadding() + ", sequence-id=" + ri.getSequenceId() );
        }

        String el = c.getEmptyList();
        if ( el != null )
        {
            System.out.println( "EmptyList: " + el );
        }
    }


    /**
     *
     * @param ev
     */
    public static void displayEmptyV( EmptyV ev )
    {
        System.out.print( "\tEMPTYV\t" );
        List<ColInfo> colis = ev.getColInfo();
        Iterator colis_it = colis.iterator();
        while ( colis_it.hasNext() )
        {
            ColInfo coli = (ColInfo) colis_it.next();
            System.out.println( "ColInfo: cell-size-h = " + coli.getCellSizeH() );
        }

        List<EmptyV> evs = ev.getEmptyV();
        Iterator evs_it = evs.iterator();
        while ( evs_it.hasNext() )
        {
            EmptyV sub_ev = (EmptyV) evs_it.next();
            displayEmptyV( sub_ev );
        }
    }

}
